
#define D2D_INPUT_COUNT 2
//hlsl帮助程序库
#include "d2d1effecthelpers.hlsli"

float3 startColor = float3(1, 0, 0);
float3 endColor = float3(0, 1, 0);
float threshold = 0;
float width = 0.1;
//方向，0：无，1上，2下，3坐，4右，5中心，6指定位置；
float2 startPos;
int model =0;
D2D_PS_ENTRY(main){

    //获取当前像素
    float4 color = D2DGetInput(0);
        //获取当前像素在屏幕上的坐标（相对位置）
    float2 pos = D2DGetInputCoordinate(0).xy;
        //按百分比进行采样 获取噪点图当前点的像素颜色
    float3 dissolve = D2DSampleInput(1, pos).rgb;
    float args = 0;
    //无方向
    if(model ==0){
        args =dissolve.r- threshold;
    }
    else if(model==1){
        //由上至下
        args =-(threshold/pos.y  - dissolve.r);
    }
    else if(model==2){
        //由下至上
        args =-(threshold/ (1-pos.y)  - dissolve.r);
    }
    else if(model==3){
        //由左至右
        args =-(threshold/pos.x  - dissolve.r);
    }
    else if(model==4){
        //由右至坐
        args =-(threshold/ (1-pos.x)  - dissolve.r);
    }
    else if(model==5){
        float dist = length(pos-float2(0.5,0.5));
        //由中至外
        args =-(threshold/dist  - dissolve.r);
    }
    else{
         float dist = length(pos-startPos);
        //由点至外
        args =-(threshold/dist  - dissolve.r);
    }
     
    if(args<=0){
        return float4(0,0,0,0);
    }
        
    float t = 1 - smoothstep(0, width, args);
    float3 edgeColor = lerp(startColor, endColor, float3(t, t, t));
    edgeColor =pow(edgeColor,5);
    t=t*step(0.0001,threshold);
    float3 finalColor = lerp(color, edgeColor, float3(t, t, t));
    return float4(finalColor,color.a);

   
}